package com.mdb.open.trade.service.product;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mdb.bc.database.mybatisplus.SuperService;
import com.mdb.enums.CustomerTypeEnum;
import com.mdb.open.trade.common.MdbDataSource;
import com.mdb.open.trade.domain.po.product.RateUserProd;
import com.mdb.open.trade.mapper.product.RateUserProdMapper;
import org.springframework.stereotype.Service;

/**
 * 类描述：
 *  费率客户产品表 服务类
 *
 * @author liuyi
 * @date 2019-07-08
 */
@Service
@DS(MdbDataSource.PRODUCT)
public class RateUserProdService extends SuperService<RateUserProdMapper, RateUserProd> {

    /**
     * 获取客户产品费率
     */
    public RateUserProd getCustomerRate(String customerCode, String prodCode) {
        return this.baseMapper.selectOne(new LambdaQueryWrapper<RateUserProd>()
                .eq(RateUserProd::getProdCode, prodCode)
                .eq(RateUserProd::getType, CustomerTypeEnum.CUSTOMER.getValue())
                .eq(RateUserProd::getUserNo, customerCode));
    }

    /**
     * 获取商户产品费率
     */
    public RateUserProd getMerchantRate(String customerCode, String prodCode, String merchantNo) {
        return this.baseMapper.selectOne(new LambdaQueryWrapper<RateUserProd>()
                .eq(RateUserProd::getProdCode, prodCode)
                .eq(RateUserProd::getType, CustomerTypeEnum.MERCHANT.getValue())
                .eq(RateUserProd::getPUserNo, customerCode)
                .eq(RateUserProd::getUserNo, merchantNo));
    }
}
